<?php

namespace addons\weblog;

use app\common\library\Menu;
use think\Addons;

/**
 * 网站日志分析插件
 */
class Weblog extends Addons
{
    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'weblog',
                'title'   => '网站日志分析助手',
                'icon'    => 'fa fa-crop',
                'sublist' => [
                    [
                        'name'    => 'weblog/log',
                        'title'   => '数据统计管理',
                        'icon'    => 'fa fa-circle-o',
                        'sublist' => [
                            ['name' => 'weblog/log/index',  'title' => '查看'],
                            ['name' => 'weblog/log/edit',   'title' => '详情'],
                            ['name' => 'weblog/log/del',    'title' => '删除'],
                            ['name' => 'weblog/log/site',   'title' => '站点占比统计'],
                            ['name' => 'weblog/log/spider', 'title' => '蜘蛛占比统计'],
                            ['name' => 'weblog/log/url',    'title' => 'URL流量统计'],
                            ['name' => 'weblog/log/ip',     'title' => 'IP流量统计'],
                            ['name' => 'weblog/log/code',   'title' => '访问状态统计'],
                        ]
                    ],
                    [
                        'name'    => 'weblog/site',
                        'title'   => '站点管理',
                        'icon'    => 'fa fa-circle-o',
                        'sublist' => [
                            ['name' => 'weblog/site/index', 'title' => '查看'],
                            ['name' => 'weblog/site/del',   'title' => '删除'],
                        ]
                    ],
                    [
                        'name'    => 'weblog/code',
                        'title'   => '状态码管理',
                        'icon'    => 'fa fa-circle-o',
                        'sublist' => [
                            ['name' => 'weblog/code/index', 'title' => '查看'],
                            ['name' => 'weblog/code/add',   'title' => '添加'],
                            ['name' => 'weblog/code/edit',  'title' => '编辑'],
                            ['name' => 'weblog/code/del',   'title' => '删除'],
                        ]
                    ],
                    [
                        'name'    => 'weblog/spider',
                        'title'   => '蜘蛛管理',
                        'icon'    => 'fa fa-circle-o',
                        'sublist' => [
                            ['name' => 'weblog/spider/index', 'title' => '查看'],
                            ['name' => 'weblog/spider/add',   'title' => '添加'],
                            ['name' => 'weblog/spider/edit',  'title' => '编辑'],
                            ['name' => 'weblog/spider/del',   'title' => '删除'],
                        ]
                    ]
                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('weblog');
        return true;
    }

    /**
     * 插件启用方法
     */
    public function enable()
    {
        Menu::enable('weblog');
    }

    /**
     * 插件禁用方法
     */
    public function disable()
    {
        Menu::disable('weblog');
    }

    /**
     * 应用初始化
     */
    public function appInit()
    {
        \think\Console::addDefaultCommands(['addons\weblog\library\Import']);
    }
}
